package android_design_mode.chapter09_chain_of_responsibility.chainv2;

public abstract class AbstractHandler {

    protected AbstractHandler nextHandler;

    public final void handleRequest(AbstractRequest request) {
        if (getHandlerLevle() == request.getRequestLevel()) {
            handle(request);
        } else {
            if (nextHandler != null) {
                nextHandler.handle(request);
            } else {
                System.out.println("All of handlers can not handle the request!");
            }
        }
    }

    protected abstract int getHandlerLevle();

    protected abstract void handle(AbstractRequest request);

}
